<template>
  <div class="region">
    <div class="content">
      <div class="left">
        地区：
      </div>
      <ul>
        <li :class="{active:activeFlag===''}" @click="changeActiveFlag('')">全部</li>
        <li v-for="item in regionList" :key="item.id" :class="{active:item.value===activeFlag}" @click="changeActiveFlag(item.value)">
          {{item.name}}
        </li>
      </ul>
    </div>
  </div>
</template>
<script setup lang="ts">
import {onMounted, ref} from 'vue'
import {HospitalLevelOrRegion} from "@/api/home/type.ts";
import {reqHospitalLevelOrRegion} from "@/api/home";
const $emit = defineEmits(['getRegion'])
const regionList = ref<HospitalLevelOrRegion[]>([])
const activeFlag = ref<string>('')
onMounted(()=>{
  getRegionList()
})
const getRegionList = async ()=>{
  const result = await reqHospitalLevelOrRegion('Beijin')
  console.log(result)
  regionList.value = result.data
}
const changeActiveFlag = (region:string)=>{
  activeFlag.value = region
  $emit('getRegion',region)
}
</script>

<style scoped lang="scss">
.region{
  color: #7f7f7f;
  margin-top: 10px;
  .content{
    display: flex;
    .left{
      margin-right: 10px;
      width: 50px;
    }
    ul{
      display: flex;
      flex-wrap: wrap;
      li{
        margin-right: 10px;
        margin-bottom: 10px;
        &.active{
          color: #55a6fe;
        }
      }
      li:hover{
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
